<template>
  <tl-sub-page :render="render" :visible.sync="visible" v-dialogDrag :title="title" :close-on-click-modal="false" class="tl-dialog" width="1200px" @open="open" @close="close">
    <el-tabs v-model="activeTabName" type="card" @tab-click="tabClick">
      <el-tab-pane label="基础信息" name="basic">
        <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="150px" :disabled="disableEditSubmit || disableSave">
					<el-row>
						<el-col :span="12">
							<el-form-item label="项目id" prop="projectid" >
								<el-input-number v-model="model.projectid" controls-position="right" :step="1" :min="0" style="width:100%"></el-input-number>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="项目名称" prop="projectname" >
								<el-input v-model="model.projectname"></el-input>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="12">
							<el-form-item label="项目编号" prop="projectcode" >
								<el-input v-model="model.projectcode"></el-input>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="Owner" prop="owner" >
								<el-input v-model="model.owner"></el-input>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="12">
							<el-form-item label="Owner工号" prop="ownercode" >
								<el-input v-model="model.ownercode"></el-input>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="项目经理" prop="projectmanager" >
								<el-input v-model="model.projectmanager"></el-input>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="12">
							<el-form-item label="项目经理工号" prop="projectmanagercode" >
								<el-input v-model="model.projectmanagercode"></el-input>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="24">
							<el-form-item label="项目成果" prop="achievements" >
								<el-input v-model="model.achievements" type="textarea" :rows="4"></el-input>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="24">
							<el-form-item label="计划目标" prop="planningtarget" >
								<el-input v-model="model.planningtarget" type="textarea" :rows="4"></el-input>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="24">
							<el-form-item label="实际结果" prop="actualresult" >
								<el-input v-model="model.actualresult" type="textarea" :rows="4"></el-input>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="24">
							<el-form-item label="差异分析" prop="differenceanalysis" >
								<el-input v-model="model.differenceanalysis" type="textarea" :rows="4"></el-input>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="12">
							<el-form-item label="结项金额" prop="settlementmoney" >
								<el-input-number v-model="model.settlementmoney" controls-position="right" :step="1" :min="0" style="width:100%"></el-input-number>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="24">
							<el-form-item label="结项说明" prop="projectdescription" >
								<el-input v-model="model.projectdescription" type="textarea" :rows="4"></el-input>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="12">
							<el-form-item label="结项时间" prop="enddate" >
								<el-date-picker v-model="model.enddate" type="date" placeholder="结项时间" value-format="yyyy-MM-dd"></el-date-picker>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="复盘编号" prop="reviewcode" >
								<el-input v-model="model.reviewcode"></el-input>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="12">
							<el-form-item label="结项类型" prop="endtype" >
								<el-input v-model="model.endtype"></el-input>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="经验教训" prop="experience" >
								<el-input v-model="model.experience"></el-input>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="12">
							<el-form-item label="所属公司" prop="orgcode" >
								<el-input v-model="model.orgcode"></el-input>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="所属部门" prop="deptcode" >
								<el-input v-model="model.deptcode"></el-input>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="12">
							<el-form-item label="申请人姓名2" prop="username" >
								<el-input v-model="model.username"></el-input>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="申请人工号2" prop="usercode" >
								<el-input v-model="model.usercode"></el-input>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="12">
							<el-form-item label="申请公司编码" prop="applyorgcode" >
								<el-input v-model="model.applyorgcode"></el-input>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="12">
							<el-form-item label="申请部门" prop="applydeptname"  :rules="rules.validateRequire">
								<tl-ref-dept v-model="model.applydeptname" :initDisplayData.sync="model.dispapplydeptname" dataType="code" nameType="fullname" :singleSelect="true"></tl-ref-dept>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="申请部门编码" prop="applydeptcode" >
								<el-input v-model="model.applydeptcode"></el-input>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="12">
							<el-form-item label="申请人姓名" prop="applyusername"  :rules="rules.validateRequire">
								<tl-ref-user v-model="model.applyusername" :initDisplayData.sync="model.dispapplyusername" dataType="code" :singleSelect="true"></tl-ref-user>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="申请人工号" prop="applyusercode" >
								<el-input v-model="model.applyusercode"></el-input>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="12">
							<el-form-item label="提交时间" prop="submitdate" >
								<el-date-picker v-model="model.submitdate" type="date" placeholder="提交时间" value-format="yyyy-MM-dd"></el-date-picker>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="审批流程" prop="flowid" >
								<el-select v-model="model.flowid" filterable clearable>
									<el-option v-for="item in codeModel.flowidList" :key="item.id" :label="item.name" :value="parseInt(item.id)" />
								</el-select>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="12">
							<el-form-item label="状态" prop="state" >
								<el-select v-model="model.state" filterable clearable>
									<el-option v-for="item in codeModel.stateList" :key="item.code" :label="item.name" :value="parseInt(item.code)" />
								</el-select>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="24">
							<el-form-item label="备注" prop="description" >
								<el-input v-model="model.description" type="textarea" :rows="4"></el-input>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="24">
							<el-form-item label="项目概述" prop="summary" >
								<el-input v-model="model.summary" type="textarea" :rows="4"></el-input>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="12">
							<el-form-item label="排序码" prop="sortcode">
								<el-input-number v-model="model.sortcode" controls-position="right" :step="1" :min="0" style="width:100%"></el-input-number>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="有效" prop="enabled">
								<el-radio-group v-model="model.enabled">
									<el-radio :label="parseInt(item.code)" v-for="item in codeModel.enabledList" :key="item.code">{{ item.name }}</el-radio>
								</el-radio-group>
							</el-form-item>
						</el-col>
					</el-row>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="明细" name="line">
        <!-- <tl-line ref="line" :parentId="model.id" :editable="!disableSave"></tl-line> -->
      </el-tab-pane>
    </el-tabs>
    <tl-approval-history ref="history" sourceType="GpmProjectReview" :sourceId="model.id" />
    <div slot="footer" class="dialog-footer">
      <el-button :type="disableEditSubmit === false ? 'text' : 'primary'" @click="doCancelEdit">取消</el-button>
      <el-button type="primary" @click="doSubmitEdit" :loading="saveLoading" v-if="!disableEditSubmit" :disabled="disableSave"><svg-icon icon-class="save" />保存</el-button>
      <el-button type="primary" @click="doSubmitApproval" :loading="submitLoading" v-if="!disableEditSubmit" :disabled="disableApproval"><svg-icon icon-class="send" />提交审批</el-button>
      <tl-attachment sourceType="GpmProjectReview" :sourceId="model.id" :disabled="disableAttachment" :editable="stateEdit"></tl-attachment>
      <el-button type="primary" @click="$refs.history.visible = true" :disabled="disableApprovalHistory"><svg-icon icon-class="list" />审批历史</el-button>
      <!-- <el-button type="primary" @click="doDelApproval" :loading="delApprovalLoading" v-if="!disableEditSubmit" :disabled="disableDelApproval"><svg-icon icon-class="undo" />取消审批</el-button> -->
    </div>
  </tl-sub-page>
</template>

<script>
/** mixins */
import { mixin_approval_edit } from '@tapui/mixins/mixin_approval_edit'
/** 子组件 */
// import tlLine from '../sdProjectReviewLine/indexFrame'
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
/** VUE配置 */
export default {
  mixins: [mixin_approval_edit],
//   components: { tlLine },
  data() {
    return {
      moduleTitle: 'SD项目复盘结项',
      urlPrefix: '/sd/projectReview/',
      url: {
        // 额外的url
      },
      activeTabName: 'basic',
      isRefreshLine: false
    }
  },
  methods: {
    assignDefaultValue() {
      if (this.isAdd) {
        if (this.codeModel.flowidList && this.codeModel.flowidList.length > 0) {
          this.$set(this.model, 'flowid', parseInt(this.codeModel.flowidList[0].id))
        }
        this.$set(this.model, 'orgcode', this.org.code)
        this.$set(this.model, 'orgname', this.org.name)
        this.$set(this.model, 'deptcode', this.dept.code)
        this.$set(this.model, 'deptname', this.dept.fullname)
        this.$set(this.model, 'usercode', this.user.code)
        this.$set(this.model, 'username', this.user.name)
      }
    },
    loaded() {
      // 页面加载完毕执行
      this.activeTabName = 'basic'
      this.isRefreshLine = false
      if (!this.isAdd && this.model.docno) {
        this.title = this.title + `（单据编号：${this.model.docno}）`
      }
    },
    tabClick(tab) {
      if (tab.name === 'line') {
        if (!this.model.id) {
          this.$nextTick((_) => {
            this.activeTabName = 'basic'
          })
          this.$tap
            .confirm('当前数据未保存，是否立即保存数据？')
            .then((_) => {
              this.doSubmitEdit()
            })
            .catch((_) => {})
        } else if (!this.isRefreshLine) {
          this.$refs.line.doQuery()
          this.isRefreshLine = true
        }
        this.$refs.line.initPage()
      }
    }
  }
}
</script>

